﻿using System;
using System.Windows.Forms;

namespace CloudDetector.RasterMap
{
    /// <summary>
    /// A betöltött képek navigációját kezelő osztály
    /// </summary>
    public partial class NavigatorControl : UserControl
    {
        #region Fields

        private Map rasterMap;
        private Int32 zoomLevel;
        
        #endregion

        #region Properties

        public Map RasterMap
        {
            set { rasterMap = value; }
            get { return rasterMap; }
        }

        #endregion

        #region Constructor

        public NavigatorControl()
        {
            InitializeComponent();

            zoomLevel = 100;
        }

        #endregion

        #region Event handlers

        private void ButtonRight_Click(object sender, EventArgs e)
        {
            if (rasterMap != null) rasterMap.Right();
        }

        private void ButtonLeft_Click(object sender, EventArgs e)
        {
            if (rasterMap != null) rasterMap.Left();
        }

        private void ButtonUp_Click(object sender, EventArgs e)
        {
            if (rasterMap != null) rasterMap.Up();
        }

        private void ButtonDown_Click(object sender, EventArgs e)
        {
            if (rasterMap != null) rasterMap.Down();
        }

        private void ButtonPlus_Click(object sender, EventArgs e)
        {
            if (zoomLevel < 1000) zoomLevel += 10;
            trackZoom.Value = zoomLevel;
            labelZoomLevel.Text = zoomLevel.ToString() + "%";
            if (rasterMap != null) rasterMap.NavZoomLevel = zoomLevel;
        }

        private void ButtonMinus_Click(object sender, EventArgs e)
        {
            if (zoomLevel > 11) zoomLevel -= 10;
            else if (zoomLevel > 1) zoomLevel--;
            trackZoom.Value = zoomLevel;
            labelZoomLevel.Text = zoomLevel.ToString() + "%";
            if (rasterMap != null) rasterMap.NavZoomLevel = zoomLevel;
        }

        private void TrackZoom_Scroll(object sender, EventArgs e)
        {
            zoomLevel = trackZoom.Value;
            labelZoomLevel.Text = zoomLevel.ToString() + "%";
            if (rasterMap != null) rasterMap.NavZoomLevel = zoomLevel;
        }

        private void ButtonReset_Click(object sender, EventArgs e)
        {
            zoomLevel = 100;
            trackZoom.Value = zoomLevel;
            labelZoomLevel.Text = zoomLevel.ToString() + "%";
            if (rasterMap != null) rasterMap.Reset();
        }

        #endregion
    }
}
